import { createConnection, Connection } from "mysql2";
import config from "../config/default.js";
import loginMag from "./loginInfo.js";
import menu from "./getmenu.js";

const connection = createConnection({
  host: config.mysqlconfig?.host, // 数据库服务器地址
  user: config.mysqlconfig?.user, // 数据库用户名
  password: config.mysqlconfig?.password, // 数据库密码
  database: config.mysqlconfig?.database // 数据库名
}) as Connection;

// 开启数据库连接
connection.connect(function (error: any) {
  if (error) throw error;
  console.log('数据库连接成功!');
});

export let loginInfo = (username: any, password: any) => loginMag(connection, username, password);
export let getmenu = (username: any, password: any) => menu(connection, username, password);